<?php

    class Accueil_m extends Model {

        function Accueil_m() {
            parent::Model();
            $this->load->database();
        }

        function get_user($email, $password) {
            $this->db->select('lehu_users.id,lehu_users.email,lehu_users.password,lehu_users.group_id,lehu_profiles.display_name');
            $this->db->from('lehu_users');
            $this->db->join('lehu_profiles', 'lehu_profiles.user_id = lehu_users.id');
            $this->db->where(array('lehu_users.email' => $email, 'lehu_users.password' => $password));
            $query = $this->db->get();
            return $query;
        }

        function get_avatar_user($account_id) {
            if ($account_id > 0) {
                $this->db->select('lehu_profiles.gravatar');
                $this->db->from('lehu_profiles');
                $this->db->where('lehu_profiles.user_id', $account_id);
                $query = $this->db->get();
                return $query;
            }
            return array();
        }

        function change_login_time($data, $userid) {
            $this->db->update('lehu_users', $data, array('id' => $userid));
        }

        function get_exist_email($email) {
            $query = $this->db->get_where('lehu_users', array('email' => $email));
            return $query;
        }

        function get_exist_username($username) {
            $query = $this->db->get_where('lehu_users', array('username' => $username));
            return $query;
        }

        function register_user($data) {
            $query = $this->db->insert('lehu_users', $data);
            return $query;
        }

        function register_profile($data) {
            $query = $this->db->insert('lehu_profiles', $data);
            return $query;
        }

        function get_user_id_max() {
            $this->db->select('MAX(id) as new_id');
            $query = $this->db->get('lehu_users');
            return $query;
        }

        function get_all_news($per_page, $off_set) {
            $this->db->select();
            $this->db->from('lehu_actualite');
            $this->db->limit($per_page, $off_set);
            $query = $this->db->get();
            return $query;
        }

        function get_news_detail($id) {
            $query = $this->db->get_where('lehu_actualite', array('id' => $id));
            return $query;
        }

        function update_news_view($data, $id) {
            $this->db->update('lehu_actualite', $data, array('id' => $id));
        }

        function get_posted_author($id) {
            $this->db->select('lehu_users.username');
            $this->db->from('lehu_users');
            $this->db->join('lehu_actualite', 'lehu_actualite.posted_by = lehu_users.id');
            $this->db->where('lehu_actualite.id', $id);
            $query = $this->db->get();
            return $query;
        }

        function insert_contact_infor($data) {
            $query = $this->db->insert('lehu_contacts', $data);
            return $query;
        }

        function update_temp_pass($email, $data) {
            return $this->db->update('lehu_users', $data, array('email' => $email));
        }

        function get_account_infor_by_email($email) {
            $this->db->select('lehu_users.id,lehu_users.username,lehu_users.email');
            $this->db->from('lehu_users');
            $this->db->where('lehu_users.email', $email);
            return $this->db->get();
        }

        function get_card_vip() {
            $this->db->select('id,title,content,image');
            $this->db->from('seating_text');
            $this->db->where('id','CARTE FIDELITE');
            $this->db->limit(1);
            $query = $this->db->get();
            return $query->result_array();
        }
        function add_commande($data){
            $query=$this->db->insert('zoo_commande',$data);
            return $query;
        }
        function get_my_commande($data1){
            $this->db->select();
            $this->db->from('zoo_commande');
            $this->db->where($data1);
            $this->db->order_by('id','DESC');
            $query = $this->db->get();
            return $query->row_array();
        }
        function add_detail_commande($data){
            $query=$this->db->insert('zoo_detail_commande',$data);
            return $query;
        }
        function get_detail_commande($id_commande){
            $this->db->select();
            $this->db->from('zoo_detail_commande');
            $this->db->where('idcommande',$id_commande);
            $query = $this->db->get();
            return $query->result_array();
        }
        function update_user($data,$id){
            return $this->db->update('lehu_users',$data,array('id'=>$id));   
        }
        function update_product($data,$id){
            return $this->db->update('zoo_produit',$data,array('id'=>$id));
        }
        function update_commande($data,$id){
            return $this->db->update('zoo_commande',$data,array('id'=>$id));
        }
        function get_day_allow_by_level($level) {
            $this->db->select('day_allow');
            $this->db->from('animus_anounce_level');
            $this->db->where('id', $level);
            $this->db->order_by('id DESC');
            return $this->db->get();
        }
    }

?>
